//////////////////////////////////////////////////////////////////////
//
//	Crytek CryENGINE Source code
//
//	File:ReadSequencerThread.h
//  Description: Loading file data ahead for fast load from DVD
//    Usually all CVars has to be set into release state for proper work of file sequencer:
//
//	History:
//	  -May 24,2010: Created by Vladimir Kajalin
//
//////////////////////////////////////////////////////////////////////

#ifndef __READSEQUENCERTHREAD_H__
#define __READSEQUENCERTHREAD_H__

#pragma once


//#define FS_DEBUG

struct SSeqHeader
{
  SSeqHeader() { Reset(); } 
  void Reset() 
  { 
#ifdef FS_DEBUG
    szFileName[0]=szCallStack[0]=0;
#endif
    nFileNameLen=nBlockGroupSize=sMarker[0]=nSize=nCount=nItemsRead=0; nSeek=-1; 
  } 
  char sMarker[4];
  int nSize;
  int nCount;
  int nItemsRead;
  int nSeek;
  int nBlockGroupSize;
  int nFileNameLen;

#ifdef FS_DEBUG
  char szCallStack[1024];
  char szFileName[1024];
#endif
} ;

class CReadSequencerThread : public CrySimpleThread<>
{
public:
  CReadSequencerThread(const char * szFileName);  
  ~CReadSequencerThread();  
  int Fread(void *pData, size_t nSize, size_t nCount, FILE * hFile);  
  static int FreadLowLevel(void *pData, size_t nSize, size_t nCount, FILE * hFile);

protected:
  virtual void Run();  
  virtual void Cancel() { m_bContinue = false; }

protected:
  bool m_bContinue;
  bool m_bDone;
  bool m_bEOF;
  string m_sFileName;
  byte * m_pBuffer, * m_pBufferAsync;
  int m_nLoadedStart;
  int m_nLoadedEnd;
  int m_nSeek;
  int m_nSeqBufferSize;
  int m_nSeqChunkSize;
  CryCriticalSection m_csRead;
};
#endif
